<?php

/**
 * Description of Rowset
 *
 * @author user3
 */
class Ga_Db_Rowset extends Zend_Db_Table_Rowset_Abstract {

    protected $_linkSet;

    public function getMap($fieldKey)
    {
        $result = array();
        foreach ($this->_data as $row) {
            $result[$row[$fieldKey]][] = $row;
        }
        return $result;
    }

    public function setLinkSet(Ga_Db_LinkSet $linkSet)
    {
        $this->_linkSet = $linkSet;
    }

    public function getArrayPrimary()
    {
        $arrayPrimary = $this->_table->info('primary');
        $primary      = $arrayPrimary[1];
        $result       = array();
        foreach ($this->_data as $row) {
            $result[] = $row[$primary];
        }
        return $result;
    }

    public function getArrayField($field)
    {
        $result = array();
        foreach ($this->_data as $row) {
            $result[] = $row[$field];
        }
        return array_unique($result);
    }

    /**
     *
     * @return Ga_Db_LinkSet 
     */
    public function getLinkSet()
    {
        if (!$this->_linkSet) {
            $this->_linkSet = new Ga_Db_LinkSet();
        }
        return $this->_linkSet;
    }

    protected function _loadAndReturnRow($position)
    {
        $rowset = $this->_linkSet ? $this->_linkSet->findRowset($this->getTableClass()) : null;
        if (!$rowset) {
            $rowset = $this;
        }
        $row    = parent::_loadAndReturnRow($position);
        $row->setRowset($rowset);
        return $row;
    }

}